package mysql

import "gorm.io/gorm"

type House struct {
	gorm.Model
	UserId        int64   `gorm:"type:int(11);comment:用户id"`
	HouseCity     string  `gorm:"type:varchar(20);comment:房源城市"`
	Address       string  `gorm:"type:varchar(50);comment:小区地址"`
	HouseBuild    string  `gorm:"type:varchar(3);comment:楼栋号"`
	HouseFloor    string  `gorm:"type:varchar(3);comment:楼层"`
	HouseArea     int64   `gorm:"type:int(11);comment:房屋面积"`
	HousePrice    float64 `gorm:"type:decimal(10,2);comment:月租金"`
	HouseDescribe string  `gorm:"type:varchar(100);comment:房源描述"`
	HouseCover    string  `gorm:"type:varchar(300);comment:房源封面"`
	HouseStatus   int64   `gorm:"type:tinyint(1);default:1;comment:状态:1:待上架,2:以上架,3:以租赁"`
}
type Picture struct {
	gorm.Model
	HouseId    int64  `gorm:"type:int(11);comment:房源id"`
	HouseName  string `gorm:"type:varchar(20);comment:房源名称"`
	HouseCover string `gorm:"type:varchar(300);comment:房源封面"`
}

func (h *House) Create() error {
	return Db.Create(&h).Error
}

func (p *Picture) Create() error {
	return Db.Create(&p).Error
}
func (h *House) HouseInfo() error {
	return Db.Where("id = ?", h.ID).Limit(1).Find(&h).Error
}
func (h *House) UpdateGetHouse(houseId int64, houseStatus int64) error {
	return Db.Model(&House{}).Where("id = ?", houseId).Update("house_status", houseStatus).Limit(2).Find(&h).Error
}
